module.exports = function ($resource, $state, $http, $q, FileUploader, $modal, toaster) {
  
	return {

		restrict: 'AE',
		template: require('../views/noticelist.html'),
		replace: true,
		scope: {
			'saleobj': '=',
			'funobj': '=',
			'baseinfo': '=',
			'util': '=',
			'productflag' : '='
		},
		link: function (scope, elements, attrs) {
			/* 分页
			* ========================================= */
			scope.maxSize = 5;             //最多显示多少个按钮
			scope.bigCurrentPage = 1;      //当前页码
      scope.itemsPerPage = 10         //每页显示几条
      scope.obj={};
      scope.d={};

			scope.pageChanged = function () {
          var para = {
              pageNo:scope.currentPage,
              pageSize:scope.itemsPerPage,
          };
          $resource('/api/as/ggc/reviewGuide/findCompanyList', {}, {}).
          save(para, function(res){			
              if(res.errcode === 0 || res.errcode === 10003){
                  scope.a=res.data.results;					
                  console.log(scope.a);
                  console.log('上面是申报指南列表返回值') 
                  scope.bigTotalItems = res.data.totalRecord;
              }else{
                  alert(res.errmsg);
              }
          });
      };
      scope.pageChanged();

      scope.search=function(){
          var dic = {
              pageNo:scope.currentPage,
              pageSize:scope.itemsPerPage,
          }
          $resource('', {}, {}).save(dic, function(res){
              if(res.errcode === 0 || res.errcode === 10003){
                          // console.log(res);
                  scope.a=res.data.results;
                  console.log(scope.a);
                  scope.bigTotalItems = res.data.totalRecord;
              }else{
                  alert(res.errmsg);
              }
          });
      }
      // 创建项目
      scope.addProject = function (index) {
          scope.item = scope.a[index];
          scope.flag = 'create';		
          var modalInstance = $modal.open({
            template: require('../views/addproject.html'),
            controller: 'addproject',
            size: 'lg',
            resolve: {
              items: function () {
                return scope.item;
              },
              flag: function () {
                return scope.flag;
              }
            }
          });
          modalInstance.result.then(function (showResult) {	
              scope.productflag++;
          });
      }
      scope.add = function () {
          scope.item = scope.a;			
          var modalInstance = $modal.open({
            template: require('../views/addnotice.html'),
            controller: 'addnotice',
            size: 'lg',
            resolve: {
              items: function () {
                return scope.item;
              }
            }
          });
          modalInstance.result.then(function (showResult) {	
              scope.pageChanged();
          });
      }
      // 详情
      scope.toinfo= function (index) {
        scope.item = scope.a[index];			
        var modalInstance = $modal.open({
          template: require('../views/noticeinfo.html'),
          controller: 'noticeinfo',
          size: 'lg',
          resolve: {
            items: function () {
              return scope.item;
            }
          }
        });
        modalInstance.result.then(function (showResult) {	
            scope.pageChanged();
        });
    }

    scope.edit= function (index) {
        scope.item = scope.a[index];			
        var modalInstance = $modal.open({
          template: require('../views/noticeupdate.html'),
          controller: 'noticeupdate',
          size: 'lg',
          resolve: {
            items: function () {
              return scope.item;
            }
          }
        });
        modalInstance.result.then(function (showResult) {	
            scope.pageChanged();
        });
    }
    scope.issue= function (index) {    
        console.log(scope.a[index].id) ;          
        if(confirm('是否发布该条指南？')){
            $resource('/api/as/ggc/reviewGuide/updateUp', {}, {}).save({'id':scope.a[index].id}, function(res){			              
              if(res.errcode === 0 || res.errcode === 10003){
                  alert('发布成功')			
                  scope.pageChanged();
              }else{
                  alert(res.errmsg);
              }
          });
        }		
    }

    scope.down= function (index) {    
        console.log(scope.a[index].id) ;          
        if(confirm('下线？')){
            $resource('/api/as/ggc/reviewGuide/updateDown', {}, {}).save({'id':scope.a[index].id}, function(res){			              
                if(res.errcode === 0 || res.errcode === 10003){
                    alert('下线成功')			
                    scope.pageChanged();
                }else{
                    alert(res.errmsg);
                }
            });
        }		
    }

			// scope.$watch('examineflag', function(){
			// 	scope.pageChanged();
			// }, true)
			

    }
	}
}